//
//  UIButton+WTBlock.m
//  66TV
//
//  Created by ben on 16/9/6.
//  Copyright © 2016年 shifeng. All rights reserved.
//

#import "UIButton+WTBlock.h"
#import <objc/runtime.h>

@implementation UIButton (WTBlock)
static char ActionTag;
- (void)addAction:(WTUIButtonBlock)block{
    
    objc_setAssociatedObject(self, &ActionTag, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
    [self addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)action:(id)sender{
    
    WTUIButtonBlock blockAction = (WTUIButtonBlock)objc_getAssociatedObject(self, &ActionTag);
    if (blockAction)
    {
        blockAction();
    }
}
@end
